const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')


module.exports = {
  entry: './src/main.js',
  output: {
    filename: '[name]-[hash].js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        use: ['vue-loader']
      },
      {
        test: /\.css$/,
        use: ['vue-style-loader', 'css-loader']
      },
      {
        test: /\.less$/,
        use: [{
          loader: "style-loader" // creates style nodes from JS strings
        }, {
          loader: "css-loader" // translates CSS into CommonJS
        }, {
          loader: "less-loader" // compiles Less to CSS
        }]
      },
      // {
      //   test: /.js$/,
      //   use: {
      //     loader: 'babel-loader',
      //     options: {
      //       presets: ['@babel/preset-env']
      //     }
      //   }
      // },
      // {
      //   test: /.css$/, // 匹配文件
      //   use: ['style-loader', 'css-loader'] // 使用插件 ，从后往前执行
      // },
      // {
      //   test: /\.less$/,
      //   use: [
      //     'style-loader',
      //     { loader: 'css-loader', options: { importLoaders: 1 } },
      //     'less-loader'
      //   ]
      // },
      {
        test: /.png$/,
        use: 'url-loader'
      },
      // {
      //   loader: 'url-loader',
      //   options: {
      //     limit: 10 * 1024 // 10kb，如果使用限制，就必须安装file-loader
      //   }
      // },
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: '1234',
      filename: 'index.html',
      template: './public/index.html',
      url: 'https://www.123.com'
    }),
    new VueLoaderPlugin()
  ]
}